﻿using Coldairarrow.Business.PersonalCenter;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PersonalCenter;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PersonalCenter
{
    [Route("/PersonalCenter/[controller]/[action]")]
    public class BTB_browseController : BaseApiController
    {
        #region DI

        public BTB_browseController(IBTB_browseBusiness bTB_browseBus)
        {
            _bTB_browseBus = bTB_browseBus;
        }

        IBTB_browseBusiness _bTB_browseBus { get; }

        #endregion

        #region 获取
        /// <summary>
        /// 查询用户浏览记录----分页查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<BTB_GoodsDto>> GetDataList(PageInput<BTB_GoodsDto> input)
        {
            return await _bTB_browseBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 热销产品
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<GoodsPrice> HotSale()
        {
            return _bTB_browseBus.HotSale();
        }
        #endregion

        #region 提交
        /// <summary>
        /// 添加或修改个人浏览记录
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(BTB_browse data)
        {
            if (data.id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _bTB_browseBus.AddDataAsync(data);
            }
            else
            {
                await _bTB_browseBus.UpdateDataAsync(data);
            }
        }
        /// <summary>
        /// 删除个人浏览记录
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _bTB_browseBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}